<template>
  <el-dialog append-to-body :title="title" :visible.sync="dialogFormVisible" width="30vw" @close="close">
    <el-form ref="form" label-width="auto" :model="form" :rules="rules">
      <el-form-item label="新密码" prop="newPsw">
        <el-input v-model="form.newPsw" autocomplete="off" />
      </el-form-item>
      <el-form-item label="确认密码" prop="newRePsw">
        <el-input v-model="form.newRePsw" autocomplete="off" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save(form)">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { AccountPwdChange } from '@/api/userManagement'
  export default {
    name: 'PswEdit',
    data() {
      return {
        uploadFileList: [],
        form: {
          id: 0,
          newPsw: '',
          newRePsw: '',
        },
        rules: {
          newPsw: [{ required: true, trigger: 'blur', message: '请输入新密码' }],
          newRePsw: [{ required: true, trigger: 'blur', message: '请确认新密码' }],
        },
        title: '修改密码',
        dialogFormVisible: false,
        options: [],
      }
    },
    created() {},
    methods: {
      async showEdit(row) {
        this.form = Object.assign({}, row)
        this.dialogFormVisible = true
      },
      close() {
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        this.dialogFormVisible = false
      },

      save(form) {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            if (form.newPsw != form.newRePsw) {
              this.$baseMessage('两次输入密码不一致', 'error')
            } else {
              console.log(1231231)
              let { msg } = await AccountPwdChange(form)
              this.$baseMessage(msg)
              this.$emit('fetch-data')
              this.close()
            }
          } else {
            return false
          }
        })
      },
    },
  }
</script>
<style lang="scss" scoped>
  .el-form-item ::v-deep .el-select {
    width: 100%;
  }
</style>
